<script src="/public/static/js/jquery.min.js"></script>
<script src="/public/static/plugin/layer/layer.js"></script>
<style>
	.contain{
		margin-top: 10px;
		padding-left: 10px;
		font-size:13px;
		margin-right: 10px;
		font-family: 微软雅黑, "Source Sans Pro", sans-serif;
		width: 700px;
		margin-top: 10px;
	}
	.from_i_s{
		height: 20px;
        line-height: 20px;
        padding: 0px 5px;
        width: 120px;
        border-radius: 4px;
        border: 1px solid #ccc;
	}
	.from_c{
		border-radius: 4px;
        border: 1px solid #ccc;
	}

	.div_line{
    	margin-left: 15px;
    	padding-bottom: 30px;
    }
    
    .div_line_one{
    	float: left;
    	width: 80px;
    	text-align: right;
    }
    .div_line_two{
    	width: 85%;
    	float: left;
    }
	.div_line_two ul{
    	display: inline-block;
        padding: 0;
        margin: 0;
        line-height: 30px;
    }
    .div_line_two ul li{
    	list-style: none;
        display: inline-block;
        margin-right: 10px;
        padding: 0;
        
    }
    h4 { font-size: 13px; font-weight: normal; color: #666; text-align: right; vertical-align: top; display: inline-block; *display: inline/*IE7*/;
 margin-right: 1%; *zoom: 1;margin-left: 5px;margin-top: 12px;margin-bottom: 5px;color: #009f95;font-weight: bold;
}
a.ncap-btn-big {text-decoration: none;font-weight: bold 14px/20px "microsoft yahei", arial; color: #FFFFFF; background-color: #5cb85c; text-align: center; vertical-align: middle; display: inline-block; 
height: 20px; padding: 7px 19px; border: solid 1px #5cb85c; border-radius: 3px; cursor: pointer; }
a:hover.ncap-btn-big { text-decoration: none; color: #FFFFFF; background-color: #5cb85c; box-shadow: 0 0 0 2px rgba(82, 168, 236, 0.15); }
    
.s_s_c{
	float: left;
	width: 100%;
	padding-bottom: 15px;
	padding-top: 15px;
	border-bottom: 1px #009f95 dashed;
}
</style>

<div class="contain">
  <{foreach from=$list item=item key=key}>
  <div class="s_s_c">
	<div class="div_line">
        <div class="div_line_one">专服名称：</div>
        <div class="div_line_two">
            <span style="margin-left: 10px;"><{$item.special_name}></span>
        </div>
    </div>
       
    <div class="div_line" id="server" >
        <div class="div_line_one" style="padding-top: 10px;">选择服务器：</div>
        <div class="div_line_two">
        	<h4>
				<input id="cls_server" name="cls_server[]" cka='server_<{$item.special_id}>' type="checkbox">
				<label>全选</label>
			</h4><br />
            <ul id="server_ul">
            	<{foreach from=$item.server item=serverItem key=serverKey}>
            	<li>
                    <input class="from_c" ck='server_<{$item.special_id}>' name="server_id[]" type="checkbox" value="<{$serverItem.server_id}>-<{$item.special_id}>"/>
                    <label for=""><{$serverItem.server_name}>(<{$serverItem.server_num}>)</label>
                </li>
                <{/foreach}>
                <!--<li>
                    <input class="from_c" ck='server_1' name="server_id[]" type="checkbox" value=""/>
                    <label for="">服务器1</label>
                </li>-->
                
            </ul>                               
        </div>
    </div>  
    
    
    <div class="div_line" id="channel">
        <div class="div_line_one" style="padding-top: 10px;">选择渠道：</div>
        <div class="div_line_two">
        	<h4>
				<input id="cls_channel" name="cls_channel[]" cka='channel_<{$item.special_id}>' type="checkbox" value="<{$item.special_id}>">
				<label>全选</label>
			</h4><br />
            <ul id="channel_ul">
            	<{foreach from=$item.channel item=channelItem key=channelKey}>
            	<li>
                    <input class="from_c" ck='channel_<{$item.special_id}>' name="channel_id[]" type="checkbox" value="<{$channelItem.channel_id}>-<{$item.special_id}>"/>
                    <label for=""><{$channelItem.channel_name}></label>
                </li>
                <{/foreach}>
                <!--<li>
                    <input class="from_c" ck='channel_1' name="channel_id[]" type="checkbox" value=""/>
                    <label for="">渠道1</label>
                </li>-->
               
            </ul>                               
        </div>
    </div>
  </div>
  <{/foreach}>
  	
  <!--<div class="s_s_c">
	<div class="div_line">
        <div class="div_line_one">专服名称：</div>
        <div class="div_line_two">
            <span style="margin-left: 10px;">专服1</span>
        </div>
    </div>
    
    <div class="div_line" id="server" >
        <div class="div_line_one" style="padding-top: 10px;">选择服务器：</div>
        <div class="div_line_two">
        	<h4>
				<input id="cls_server" cka='server_2' type="checkbox">
				<label>全选</label>
			</h4><br />
            <ul id="server_ul">
            	<li>
                    <input class="from_c" ck='server_2' name="server_id[]" type="checkbox" value=""/>
                    <label for="">服务器1</label>
                </li>
                <li>
                    <input class="from_c" ck='server_2' name="server_id[]" type="checkbox" value=""/>
                    <label for="">服务器1</label>
                </li>
            </ul>                               
        </div>
    </div>
    
    
    <div class="div_line" id="channel">
        <div class="div_line_one" style="padding-top: 10px;">选择渠道：</div>
        <div class="div_line_two">
        	<h4>
				<input id="cls_channel" cka='channel_2' type="checkbox">
				<label>全选</label>
			</h4><br />
            <ul id="channel_ul">
            	<li>
                    <input class="from_c" ck='channel_2' name="channel_id[]" type="checkbox" value=""/>
                    <label for="">渠道1</label>
                </li>
                <li>
                    <input class="from_c" ck='channel_2' name="channel_id[]" type="checkbox" value=""/>
                    <label for="">渠道1</label>
                </li>
               
            </ul>                               
        </div>
    </div>
  </div>-->
    
    
	<div class="div_line">
		<input type="hidden" name="ids" id="ids" value="<{$ids}>" />
		<a href="JavaScript:void(0);" style="margin-top: 30px;margin-left: 70%;"  class="ncap-btn-big" id="submitBtn" data-url="<{$url}>">确认提交</a>
	</div>

</div>



<script>
    $(document).ready(function(){
		$(":checkbox[cka]").click(function(){
			var cks = $(":checkbox[ck='"+$(this).attr("cka")+"']");
			if($(this).is(':checked')){
				cks.each(function(){$(this).prop("checked",true);});
			}else{
				cks.each(function(){$(this).removeAttr('checked');});
			}
		});
		
	});
	
	
	var flag = true;
    $("#submitBtn").click(function(){
    	layer.confirm('确定同步!', {
        	    btn: ['确定','取消'] //按钮
        	    ,skin: 'layui-layer-molv'
        	}, function(){
        		var special_id = $("#special_id").val();
    	        if(special_id == ''){
    		        layer.msg('请选择专服', {icon: 2,time: 2000});
        	        return false;
    	        }
    	
    	        var arr = new Array();
                $("input[name='server_id[]']:checkbox[checked]").each(function(i){
                    arr[i] = $(this).val();
                });
                var servers = arr.join(",");
                if(servers == ''){
        	        layer.msg('请选择服务器', {icon: 2,time: 2000});
        	        return false;
                }
        
                var brr = new Array();
                $("input[name='channel_id[]']:checkbox[checked]").each(function(i){
                    brr[i] = $(this).val();
                });
                var channel = brr.join(",");
                if(channel == ''){
        	        layer.msg('请选择渠道', {icon: 2,time: 2000});
        	        return false;
                }
                               
                var crr = new Array();
                $("input[name='cls_channel[]']:checkbox[checked]").each(function(i){
                    crr[i] = $(this).val();
                });
                var cls_channel = crr.join(",");
        
                //console.log(servers);    
                if(!flag){
    		        return false;
    	        }
    	        flag = false;
    	        $("#submitBtn").text('提交中...');
    	        var index = layer.load(0, {shade: false});
        
                var url = $(this).attr('data-url');
                //console.log(url); 
                var ids = $("#ids").val();
    	        $.ajax({
    		        type : 'POST',
    		        url : url,
			        data : {'servers':servers,'channel':channel,'ids':ids,'cls_channel':cls_channel},
			        dataType :'JSON',
			        success : function(res){
				        flag = true;
				        layer.close(index);
				        $("#submitBtn").text('确认提交');
				        if(res.status == 1){					        
					        window.parent.call_back(res.msg);
				        }else{
					        layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
				        }
			        }
		        });
        		
        	}, function(){
        		//取消
            });

    });
    
    
</script>